import { message } from 'antd'
import dva from 'dva'
import createLoading from 'dva-loading'
import createHistory from 'history/createBrowserHistory'
import 'babel-polyfill'
import { uuid } from 'utils'
require("./asset/jquery.printarea.js");
require("./asset/style.css");

// 生成uuid，缓存至sessionStorage
sessionStorage.setItem('uuid', uuid())

// 1. Initialize
const app = dva({
  ...createLoading({
    effects: true,
  }),
  history: createHistory(),
  onError (error,dispatch) {
    
    if(error.message){
    	const json=JSON.parse(error.message)
    	const {pathname}=location
    	if(json.code==401){
    		if(pathname!='/login'){
    			//重新登录
    			location.href='/login'
    		}
    		
    	}else{
    		message.error(json.msg)
    	}
    }
    
  },
})

// 2. Model
app.model(require('./models/app'))

// 3. Router
app.router(require('./router'))

// 4. Start
app.start('#root')
